﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Ent.Inscripcion.Presentacion.Login" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Ingreso</title>
    <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
    <script type="text/javascript" src="Resources/Js/EntInscripcion.js"></script>
    <%--<script type="text/javascript">
        if ((typeof Range !== "undefined") && !Range.prototype.createContextualFragment) {
            Range.prototype.createContextualFragment = function (html) { var frag = document.createDocumentFragment(), div = document.createElement("div"); frag.appendChild(div); div.outerHTML = html; return frag; }; 
    }</script>--%>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" ScriptMode="Debug" runat="server" />
    <ext:Window ID="winLogin" runat="server" Height="140" ButtonAlign="Center" CenterOnLoad="true"
        Closable="false" Icon="Lock" Title="Ingrese sus datos" Width="300" BodyStyle="padding:10px;"
        Draggable="false">
        <Items>
            <ext:TextField ID="txtUsername" SelectOnFocus="true" runat="server" ReadOnly="false"
                FieldLabel="Identificación" AllowBlank="false" BlankText="La identificación es requerido."
                Text="" EnableKeyEvents="true" />
            <ext:TextField ID="txtPassword" runat="server" ReadOnly="false" InputType="Password"
                FieldLabel="Clave" AllowBlank="false" BlankText="La clave es requerida." Text="" EnableKeyEvents="true">
                <DirectEvents>
                    <KeyPress OnEvent="btnIngresar_Click" Before="
                                    if(e.getKey()==Ext.EventObject.ENTER) 
                                    {
                                        e.preventDefault();
                                        return(true);
                                    }
                                    return(false);
                                ">
                        <ExtraParams>
                            <ext:Parameter Name="Login" Value="#{txtUsername}.getValue()" Mode="Raw">
                            </ext:Parameter>
                            <ext:Parameter Name="Password" Value="#{txtPassword}.getValue()" Mode="Raw">
                            </ext:Parameter>
                        </ExtraParams>
                        <EventMask ShowMask="true" Msg="Verificando..." />
                    </KeyPress>
                </DirectEvents>
            </ext:TextField>
            <ext:LinkButton runat="server" ID="lbtRecuperar" Text="Olvido su clave?">
                <Listeners>
                    <Click Handler="#{winRecuperacion}.show();" />
                </Listeners>
            </ext:LinkButton>
        </Items>
        <Buttons>
            <ext:Button runat="server" ID="btnRegistrarse" Text="Registrarse" Icon="UserAdd">
                <Listeners>
                    <Click Handler="document.location = 'Registro.aspx';" />
                </Listeners>
            </ext:Button>
            <ext:Button ID="btnIngresar" runat="server" Text="Ingresar" Icon="Accept">
                <DirectEvents>
                    <Click OnEvent="btnIngresar_Click" Success="mensaje(response, result, el, type, action, extraParams);"
                        Failure="ManejarError();">
                        <ExtraParams>
                            <ext:Parameter Name="Login" Value="#{txtUsername}.getValue()" Mode="Raw">
                            </ext:Parameter>
                            <ext:Parameter Name="Password" Value="#{txtPassword}.getValue()" Mode="Raw">
                            </ext:Parameter>
                        </ExtraParams>
                        <EventMask ShowMask="true" Msg="Ingresando..." />
                    </Click>
                </DirectEvents>
                <Listeners>
                    <Click Handler="
                            if(!#{txtPassword}.validate() || !#{txtUsername}.validate() ) 
                            {
                                Ext.Msg.alert('Error','La identificación y/o password son campos obligatorios');
                                return false; 
                            }" />
                </Listeners>
            </ext:Button>
        </Buttons>
        <Listeners>
            <Show Handler="#{btnIngresar}.focus();" />
        </Listeners>
    </ext:Window>
    <ext:Window ID="winRecuperacion" runat="server" Height="140" ButtonAlign="Center"
        CenterOnLoad="true" Closable="false" Icon="Lock" Title="Recuperacion de clave"
        Width="300" BodyStyle="padding:10px;" Draggable="false" Hidden="true">
        <Items>
            <ext:TextField ID="txtIdentificacionR" SelectOnFocus="true" runat="server" ReadOnly="false"
                FieldLabel="Identificación" AllowBlank="false" BlankText="La identificación es requerido."
                Text="" EnableKeyEvents="true" />
        </Items>
        <Buttons>
            <ext:Button ID="btnRecuperar" runat="server" Text="Recuperar">
                <DirectEvents>
                    <Click OnEvent="btnRecuperar_Click" Success="alert('Se ha enviado a su correo electrónico la clave');#{winRecuperacion}.hide();"
                        Failure="ManejarError();">
                        <ExtraParams>
                            <ext:Parameter Name="Identificacion" Value="#{txtIdentificacionR}.getValue()" Mode="Raw">
                            </ext:Parameter>
                        </ExtraParams>
                        <EventMask ShowMask="true" Msg="Recuperando datos..." />
                    </Click>
                </DirectEvents>
                <Listeners>
                    <Click Handler="
                            if(!#{txtIdentificacionR}.validate() ) 
                            {
                                Ext.Msg.alert('Error','La identificación es obligatorio');
                                return false; 
                            }" />
                </Listeners>
            </ext:Button>
            <ext:Button runat="server" Text="Cancelar">
            <Listeners>
            <Click Handler="#{winRecuperacion}.hide();" />
            </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
    <ext:XScript ID="XScript1" runat="server">

    <script type="text/javascript">

        var mensaje = function (response, result, el, type, action, extraParams) {

            if (result.extraParamsResponse.Redireccion == '1') {
                document.location = 'Principal.aspx';
            }
            else {
                alert(result.extraParamsResponse.Mensaje);
            }
        };
    </script>
    </ext:XScript>
</body>
</html>
